package org.boulderfoodrescue.webapp.server.mobile;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.boulderfoodrescue.webapp.server.users.UserAccountsDatabase;
import org.boulderfoodrescue.webapp.shared.UserAccount;


/**
 * Servlet implementation class testServlet
 */
public class MobileLoginServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public MobileLoginServlet() {
        // TODO Auto-generated constructor stub
    }

  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String email = request.getParameter("email");
    String passcode = request.getParameter("passcode");
    UserAccount user = UserAccountsDatabase.getUser(email);
    PrintWriter out = response.getWriter();
    if(user == null || !passcode.equals(user.getPasscode())){
      out.println("No user with that email/passcode combination");
      return;
    }
      out.println("success");
      return;
  }

}